main.controller('sysManagerCtrl', ["$scope", "$rootScope", "$location", "tools", "$timeout", function ($scope, $rootScope, $location, tools, $timeout) {
    $scope.userInfo = JSON.parse(window.localStorage.getItem('userInfo'));
    $scope.pwd = {
        data: {
            oldPwd: '',
            newPwd: '',
            newPwdRe: ''
        },
        errInfo: '',
        submit: function () {
            var self = this;
            if (!self.check()) {
                return;
            }
            tools.get({
                url: "/Ibm-Client/updateUserPassword.htm",
                data: {
                    newPassword: hex_md5(self.data.newPwd),
                    originalPassword: hex_md5(self.data.oldPwd)
                },
                succ: function (resp) {
                    if (resp.success) {
                        tools.msg('修改密码成功!');

                        $timeout(function () {
                            window.location.href = '/trend-new-BI/main.html';
                        }, 1500);
                    } else {
                        tools.msg('系统繁忙,请稍后再试!');
                    }
                }
            });
        },
        check: function () {
            if (!/^[0-9|a-z|A-Z|_]+$/.test(this.data.newPwd)) {
                this.errInfo = "密码由大小写字母与数字组合而成~";
                return false;
            }
            if (this.data.newPwd != this.data.newPwdRe) {
                this.errInfo = "前后两次输入的密码不一致";
                return false;
            }
            return true;
        },
        reset: function () {
            this.data.oldPwd = this.data.newPwd = this.data.newPwdRe = this.errInfo = "";
        }
    };

    $scope.account = {
        name: '',
        errInfo: '',
        submit: function () {
            var self = this;
            tools.get({
                url: '/Ibm-Client/addSubAccount.htm',
                data: {
                    userName: self.name
                },
                succ: function (resp) {
                    if (resp.success) {
                        tools.msg('成功创建一个名为' + self.name + '的新账号!');
                        self.name = '';
                    } else {
                        tools.msg('系统繁忙,请稍后再试!');
                    }
                }
            });
        }
    }
}]);